package com.jx.lcs.integral.dao;

import org.hibernate.SQLQuery;
import org.hibernate.type.StandardBasicTypes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.tianyu.jty.common.persistence.HibernateDao;
import com.jx.lcs.integral.entity.IntegralType;

/**
 * 积分类型DAO
 * @author ty
 * @date 2015年1月22日
 */
@Repository
public class IntegralTypeDao extends HibernateDao<IntegralType, String>{

	private static final Logger logger = LoggerFactory.getLogger(IntegralTypeDao.class);
	
	public int isHaveAgentIntegral(String uid, String pcode){
		try{
			StringBuilder sb = new StringBuilder();
			sb.append("select count(*) num from tb_user_integral where uid='").append(uid).append("' and source='1'").append(" and sourceCode='").append(pcode).append("'");
			SQLQuery sqlQuery = createSQLQuery(sb.toString());
			sqlQuery.addScalar("num",StandardBasicTypes.INTEGER );
			return ((Integer)(sqlQuery.uniqueResult())).intValue();
		} catch(Exception e) {
			logger.error("--判断是否已经给该理财师增加过代理积分异常！", e);
			return 0;
		}
	}
}
